/*
  Copyright (c) 2011, Mikheev Rostislav
  Copyright (c) 2011, FreshFarsh team

  Steel Engine source code is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/**
  @author Mikheev Rostislav <hacenator@gmail.com>
  @date 13.03.2011
  @brief Window events listener interfaces source file.
*/

#include "listener.h"

namespace _STEEL_NAMESPACE {

void IListener::Listen(const WindowManager *window) {
  _window = const_cast<WindowManager *>(window);
}

bool IListener::IsListener() {
  return true;
}

//------------------------------------------

void IMouseListener::Listen(const WindowManager * window) {
  IListener::Listen(window);

  assert(_window);

  _mouse_up_listener = _window->AddListener(this, WindowManager::kListenMouseUp);
  _mouse_move_listener = _window->AddListener(this, WindowManager::kListenMouseDown);
  _mouse_move_listener = _window->AddListener(this, WindowManager::kListenMouseMove);
}

void IMouseListener::StopListen() {
  assert(_window);

  _window->RemoveListener(_mouse_up_listener);
  _window->RemoveListener(_mouse_down_listener);
  _window->RemoveListener(_mouse_move_listener);
}

//------------------------------------------

void IKeyboardListener::Listen(const WindowManager * window) {
  IListener::Listen(window);

  assert(_window);

  _key_up_listener = _window->AddListener(this, WindowManager::kListenKeyUp);
  _key_down_listener = _window->AddListener(this, WindowManager::kListenKeyDown);
}

void IKeyboardListener::StopListen() {
  assert(_window);

  _window->RemoveListener(_key_down_listener);
  _window->RemoveListener(_key_up_listener);
}

//------------------------------------------

void IWindowListener::Listen(const WindowManager * window) {
  IListener::Listen(window);

  assert(_window);

  _open_listener = _window->AddListener(this, WindowManager::kListenInit);
  _close_listener = _window->AddListener(this, WindowManager::kListenClose);
  _draw_listener = _window->AddListener(this, WindowManager::kListenDraw);
}

void IWindowListener::StopListen() {
  assert(_window);

  _window->RemoveListener(_open_listener);
  _window->RemoveListener(_close_listener);
  _window->RemoveListener(_draw_listener);
}

}
